package enums;

import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;


public enum ThirdSystemErrorEnum {
    /**支付宝支付系统错误码**/
	ACQ_SYSTEM_ERROR("ACQ.SYSTEM_ERROR", "系统错误"),
	ACQ_INVALID_PARAMETER("ACQ.INVALID_PARAMETER", "参数无效"),
	ACQ_TRADE_NOT_EXIST("ACQ.TRADE_NOT_EXIST", "交易不存在"),
	ACQ_TRADE_STATUS_ERROR("ACQ.TRADE_STATUS_ERROR", "交易状态不合法"),
	ACQ_SELLER_BALANCE_NOT_ENOUGH("ACQ.SELLER_BALANCE_NOT_ENOUGH", "卖家余额不足"),
	ACQ_REFUND_AMT_NOT_EQUAL_TOTAL("ACQ.REFUND_AMT_NOT_EQUAL_TOTAL", "退款金额超限"),
	ACQ_REASON_TRADE_BEEN_FREEZEN("ACQ.REASON_TRADE_BEEN_FREEZEN", "请求退款的交易被冻结"),
	ACQ_TRADE_HAS_FINISHED("ACQ.TRADE_HAS_FINISHED", "交易已完结"),
	ACQ_DISCORDANT_REPEAT_REQUEST("ACQ.DISCORDANT_REPEAT_REQUEST", "不一致的请求"),
	ACQ_REASON_TRADE_REFUND_FEE_ERR("ACQ.REASON_TRADE_REFUND_FEE_ERR", "退款金额无效"),
	ACQ_TRADE_NOT_ALLOW_REFUND("ACQ.TRADE_NOT_ALLOW_REFUND", "当前交易不允许退款"),
	ACQ_REFUND_FEE_ERROR("ACQ.REFUND_FEE_ERROR", "交易退款金额有误"),
	TRADE_NOT_EXIST("TRADE_NOT_EXIST", "查询退款的交易不存在"),
	ACQ_ACCESS_FORBIDDEN("ACQ.ACCESS_FORBIDDEN", "无权限使用接口"),
	ACQ_EXIST_FORBIDDEN_WORD("ACQ.EXIST_FORBIDDEN_WORD", "订单信息中包含违禁词"),
	ACQ_PARTNER_ERROR("ACQ.PARTNER_ERROR", "应用APP_ID填写错误"),
	ACQ_TOTAL_FEE_EXCEED("ACQ.TOTAL_FEE_EXCEED", "订单总金额不在允许范围内"),
	ACQ_BUYER_SELLER_EQUAL("ACQ.BUYER_SELLER_EQUAL", "买卖家不能相同"),
	ACQ_BUYER_ENABLE_STATUS_FORBID("ACQ.BUYER_ENABLE_STATUS_FORBID", "买家状态非法"),
	ACQ_SELLER_BEEN_BLOCKED("ACQ.SELLER_BEEN_BLOCKED", "商家账号被冻结"),
	ACQ_TRADE_HAS_CLOSE("ACQ.TRADE_HAS_CLOSE", "交易已经关闭"),
	ACQ_CONTEXT_INCONSISTENT("ACQ.CONTEXT_INCONSISTENT", "交易信息被篡改"),
	ACQ_TRADE_BUYER_NOT_MATCH("ACQ.TRADE_BUYER_NOT_MATCH", "交易买家不匹配"),
	ACQ_TRADE_HAS_SUCCESS("ACQ.TRADE_HAS_SUCCESS", "交易已被支付"),

	/**微信支付系统错误码**/
	INVALID_REQUEST("INVALID_REQUEST", "参数格式有误或者未按规则上传"),
	NOAUTH("NOAUTH", "商户未开通此接口权限"),
	NOTENOUGH("NOTENOUGH", "用户帐号余额不足"),
	ORDERPAID("ORDERPAID", "商户订单已支付，无需重复操作"),
	ORDERCLOSED("ORDERCLOSED", "当前订单已关闭，无法支付"),
	SYSTEMERROR("SYSTEMERROR", "系统超时"),
	APPID_NOT_EXIST("APPID_NOT_EXIST", "参数中缺少APPID"),
	MCHID_NOT_EXIST("MCHID_NOT_EXIST", "参数中缺少MCHID"),
	APPID_MCHID_NOT_MATCH("APPID_MCHID_NOT_MATCH", "appid和mch_id不匹配"),
	LACK_PARAMS("LACK_PARAMS", "缺少必要的请求参数"),
	OUT_TRADE_NO_USED("OUT_TRADE_NO_USED", "商户订单号重复,同一笔交易不能多次提交"),
	SIGNERROR("SIGNERROR", "参数签名结果不正确"),
	XML_FORMAT_ERROR("XML_FORMAT_ERROR", "XML格式错误"),
	REQUIRE_POST_METHOD("REQUIRE_POST_METHOD", "未使用post传递参数 "),
	POST_DATA_EMPTY	("POST_DATA_EMPTY", "post数据不能为空"),
	NOT_UTF8("NOT_UTF8", "未使用指定编码格式,请使用UTF8编码格式"),
	ORDERNOTEXIST("ORDERNOTEXIST", "查询系统中不存在此交易订单号"),
	REFUND_FEE_MISMATCH("REFUND_FEE_MISMATCH", "订单金额或退款金额与之前请求不一致，请核实后再试"),
	BIZERR_NEED_RETRY("BIZERR_NEED_RETRY", "并发情况下，业务被拒绝，商户重试即可解决"),
	TRADE_OVERDUE("TRADE_OVERDUE", "订单已经超过可退款的最大期限(支付后一年内可退款)"),
	ERROR("ERROR", "申请退款业务发生错误"),
	USER_ACCOUNT_ABNORMAL("USER_ACCOUNT_ABNORMAL", "退款请求失败，用户帐号注销"),
	INVALID_REQ_TOO_MUCH("INVALID_REQ_TOO_MUCH", "连续错误请求数过多被系统短暂屏蔽"),
	INVALID_TRANSACTIONID("INVALID_TRANSACTIONID", "无效transaction_id,请求参数未按指引进行填写"),
	FREQUENCY_LIMITED("FREQUENCY_LIMITED", "2个月之前的订单申请退款有频率限制"),
	REFUNDNOTEXIST("REFUNDNOTEXIST", "退款订单查询失败，订单号错误或订单状态不正确"),

	UN_KNOW_ERROR( "UN_KNOW_ERROR", "未知异常"),

	;
	private String code;

	private String message;


	ThirdSystemErrorEnum(String code, String message) {
		this.code = code;
		this.message = message;
	}

	public String getCode() {
		return code;
	}

	public String getMessage() {
		return message;
	}


	public static ThirdSystemErrorEnum getErrorEnum(String code) {
		if(StringUtils.isBlank(code)){
			return ThirdSystemErrorEnum.UN_KNOW_ERROR;
		}
		return Arrays.stream(ThirdSystemErrorEnum.values())
				.filter(p -> p.code.equals(code))
				.findAny()
				.orElse(ThirdSystemErrorEnum.UN_KNOW_ERROR);
	}
}
